// # 小程序密钥
const util = require('utils/util.js');
const request = require('utils/request.js');
const ver = require('utils/version.js')
const MultipleDate = require('utils/date.js')
App({
    ReqDoMain: ver.getVersion(),
    MultipleSelectDate: MultipleDate.MultipleDate,
    imagesURL: "https://pic.localhost.com/",
    onLaunch: function (options) {
        // 获取导航高度；
        this.screenSize()
        wx.getSystemInfo({
            success: res => {
                //导航高度
                this.globalData.navHeight = res.statusBarHeight * (750 / res.windowWidth) + 97;
                this.globalData.pageHeight = res.windowHeight * (750 / res.windowWidth)
                this.globalData.windowWidthSize = 750 / res.windowWidth
                this.globalData.ww = res.windowWidth
                this.globalData.hh = res.windowHeight
                // 记住密码
                if (wx.getStorageSync('userInfo') != '' && wx.getStorageSync('userInfo') != null) {
                    wx.switchTab({
                        url: "/pages/home/index"
                    })
                }

            },
            fail(err) {
                console.log(err);
            }
        })
    },
    onLoad: function (options) {},
    screenSize: function () {
        var that = this;
        wx.getSystemInfo({
            success: function (res) {
                //可视窗口宽度
                var ww = res.windowWidth;
                //可视窗口高度
                var hh = res.windowHeight;
                that.globalData.ww = ww;
                that.globalData.hh = hh;
            }
        })
    },
    basePost: function (url, data, successCallback, errorCallback, header) {
        request.basePost(url, data, successCallback, errorCallback, header);
    },

    baseGet: function (url, successCallback, errorCallback, isMsg, header) {
        request.baseGet(url, successCallback, errorCallback, isMsg, header);
    },
    baseForm: function (url, data, successCallback, errorCallback, header) {
        request.baseForm(url, data, successCallback, errorCallback, header);
    },

    Tips: function (opt, to_url) {
        return util.Tips(opt, to_url);
    },

    U: function (opt, url) {
        return util.U(opt, url);
    },
    /* 
        上传图片
    */
    uploadImageOne: function (opt, successCallback, errorCallback) {
        console.log(successCallback)
        console.log(errorCallback)
        return util.uploadImageOne(opt, successCallback, errorCallback)
    },
    /*
     * 合并数组
     */
    SplitArray: function (list, sp) {
        return util.SplitArray(list, sp)
    },

    /*
     * 时间格式化
     */
    formatdata: function (format,date) {
        var o = {
            "M+": date.getMonth() + 1, //month
            "d+": date.getDate(), //day
            "h+": date.getHours(), //hour
            "m+": date.getMinutes(), //minute
            "s+": date.getSeconds(), //second
            "q+": Math.floor((date.getMonth() + 3) / 3), //quarter
            "S": date.getMilliseconds() //millisecond
        }
        if (/(y+)/.test(format)) format = format.replace(RegExp.$1,
            (date.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var k in o)
            if (new RegExp("(" + k + ")").test(format))
                format = format.replace(RegExp.$1,
                    RegExp.$1.length == 1 ? o[k] :
                    ("00" + o[k]).substr(("" + o[k]).length));
        return format;
    },
    globalData: {
        navHeight: 0,
        pageHeight: 0,
        windowWidthSize: 0,
        ww: 0,
        hh: 0
    }
})